const TransformPages = require('uni-read-pages')
const {
	webpack
} = new TransformPages()
const VUE_APP_API_URL = "https://192.0.0.1:8080/"
module.exports = {
	configureWebpack: {
		devServer: {
			// port: '8080',
			disableHostCheck: true,
			proxy: {
				'/api': {
					target: VUE_APP_API_URL, //目标接口域名
					secure: true, // 是否https访问
					changeOrigin: true, //是否跨域
					pathRewrite: {
						'^/api': ''
					}
				}
			}
		},
		plugins: [
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ['path', 'name', 'aliasPath', 'meta']
					});
					return JSON.stringify(tfPages.routes)
				}, true)
			})
		]
	},
	transpileDependencies: ['luch-request', '@dcloudio/uni-ui', 'uview-ui', 'uni-simple-router'],
	chainWebpack: config => {
		//配置环境变量
		config
			.plugin('define')
			.tap(args => {
				const VUE_APP = {
					VUE_APP_API_URL: `'${VUE_APP_API_URL}'`, //测试请求地址
				}
				args[0]['process.env'] = {
					...args[0]['process.env'],
					...VUE_APP
				}
				return args
			})

		// 发行或运行时启用了压缩时会生效
		config.optimization.minimizer('terser').tap((args) => {
			const compress = args[0].terserOptions.compress
			// 非 App 平台移除 console 代码(包含所有 console 方法，如 log,debug,info...)
			compress.drop_console = true
			compress.pure_funcs = [
				'__f__', // App 平台 vue 移除日志代码
				// 'console.debug' // 可移除指定的 console 方法
			]
			return args
		})
	}
}
